package com.ls.utils.http;

import okhttp3.OkHttpClient;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName OkHttpHelper
 * @Description OkHttpClient单例模式
 * @Author TangQuanBin
 * @Date 2019/9/16 18:55
 * @Version 1.0
 **/
public class NoProxyOkHttpHelper {

    /**
     * OkHttpClient
     */
    private OkHttpClient okHttpClient;

    private NoProxyOkHttpHelper() {
        //超时时间,默认是10秒*/
        int connectTimeout = 100;
        //读超时时间,默认是10秒*/
        int writeTimeout = 100;
        //写超时时间,默认是10秒*/
        int readTimeout = 100;
        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .connectTimeout(connectTimeout, TimeUnit.SECONDS)
                .writeTimeout(writeTimeout, TimeUnit.SECONDS)
                .readTimeout(readTimeout, TimeUnit.SECONDS);
        okHttpClient = builder.build();
    }

    public static NoProxyOkHttpHelper getInstance() {
        return HttpHelperHolder.instance;
    }

    /**
     * 获取OkHttpClient
     */
    public OkHttpClient getOkHttpClient() {
        return okHttpClient;
    }

    private static class HttpHelperHolder {
        private static NoProxyOkHttpHelper instance = new NoProxyOkHttpHelper();
    }
}
